package com.jake.springboot.mybatis.mapper;

import com.jake.springboot.mybatis.domain.Person;
import com.jake.springboot.mybatis.domain.Person2;
import com.jake.springboot.mybatis.domain.PersonJson;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PersonMapper {

    @Insert("insert into person values(#{person.personId}, #{person.personJson, jdbcType=OTHER, " +
            "typeHandler=com.jake.springboot.mybatis.handler.PersonJsonHandler})")
    int insert(@Param("person") Person person);

    @Select("select * from person")
//    @Results({
//            @Result(property = "personId", column = "person_id"),
//            @Result(property = "personJson", column = "person_json",
//                    javaType = PersonJson.class,
//                    jdbcType = JdbcType.VARCHAR,
//                    typeHandler = PersonJsonHandler.class)
//    })
    List<Person> getPersons();

    @Select("select * from person")
    List<Person2> getPerson2s();

    @Update("update person set person_json = #{personJson} " +
            "where person_id = #{personId}")
    int update(@Param("personId") int personId, @Param("personJson") PersonJson personJson);

    @Select("select person_json from person where person_id = #{personId}")
    PersonJson getPersonJsonById(@Param("personId") int personId);

}
